import {reactive} from "vue";
import http from "../utils/http.js";
import {id} from "element-plus/es/locale/index";

const data = reactive({
    ordering: '-create_time',
    page: 1,
    article_data: [],
    user_avatar: true,
    article_img: true,
    add_love: 1,
    comments: -1,
    add_collect: 1,
    current_article_love: 0,
    current_article_collect: 0,
    current_article_comments: 0,
    user_id: 0,
    commentDialogVisible: false,
    your_comment: '',
    article_img_url: '',
    article_img_big: false,
    comment_list: [], // 文章评论列表
    comment_is_show: false, // 评论是否人显示
    article_id: 0, // 文章id
    second_comment_content: '', // 二级评论列表
    second_comment_is_show: false, // 二级评论是否显示
    first_comment_id: 0, // 一级评论id

    all_articles() {
        return http.get(`/articles/all/?ordering=${this.ordering}&page=${this.page}`)
    },

    add_some(id, data) {
        return http.put(`/articles/some/${id}/`, {
            add_love: data,
            user: this.user_id,
        })
    },
    add_some_collect(id, data) {
        return http.put(`/articles/some/${id}/`, {
            add_collect: data,
            user: this.user_id,
        })
    },

//     查询文章评论
    get_comments(id) {
        return http.get(`/articles/comment/${id}/`)
    },

    // 添加评论
    add_comment(user_id) {
        return http.post(`/articles/add_comment/`, {
            user: user_id,
            article: this.article_id,
            content: this.your_comment,
            // comment: 0,

        })
    },

    // 添加二级评论
    add_second_comment(user_id) {
        return http.post(`/articles/add_comment/`, {
            user: user_id,
            article: this.article_id,
            comment: this.first_comment_id,
            content: this.second_comment_content,
            level: 1,

        })
    },

    // 删除评论
    delete_comment(id) {
        return http.delete(`/articles/del/`, {
            params: {id}
        })
    }
})

export default data;